import MatchGameConfig from "./MatchGameConfig";
import { ObstacleAllType, SpecifyColor } from "./ObstacleConfig";

const { ccclass, property } = cc._decorator;

enum SquareType {
  MatchItem = 1,
  PropItem = 2,
  ObstacleItem = 3,
  Null = 4,
}

@ccclass
export default class SquareEditorItem extends cc.Component {
  @property({
    type: cc.Enum(SquareType),
    displayName: '方块类型',
    visible: true,
  })
  squareType: SquareType = SquareType.MatchItem;

  @property({
    type: cc.Enum(MatchGameConfig.MatchItemType),
    displayName: '棋子类型',
    visible() {
      return this.squareType === SquareType.MatchItem;
    },
  })
  matchType = MatchGameConfig.MatchItemType.null;

  @property({
    type: cc.Enum(MatchGameConfig.PropType),
    displayName: '道具类型',
    visible() {
      return this.squareType === SquareType.PropItem;
    },
  })
  propType = MatchGameConfig.PropType.LightingBall;

  @property({
    type: cc.Enum(ObstacleAllType),
    displayName: '障碍物类型',
    visible() {
      return this.squareType === SquareType.ObstacleItem;
    },
  })
  obstacleAllType = ObstacleAllType.Empty;

  @property({
    displayName: '障碍物血量',
    visible() {
      return this.squareType === SquareType.ObstacleItem;
    },
  })
  obstacleHp: number = -1;

  @property({
    type: cc.Enum(SpecifyColor),
    displayName: '障碍物颜色',
    visible() {
      return this.squareType === SquareType.ObstacleItem;
    },
  })
  obstacleColor = SpecifyColor.any;

  getSquareInfo() {
    switch (this.squareType) {
      case SquareType.MatchItem:
        return this.getMatchItemInfo();
      case SquareType.ObstacleItem:
        return this.getObstacleInfo();
      case SquareType.PropItem:
        return this.getPropInfo();
    }
  }

  getMatchItemInfo() {
    return `M-${this.matchType}`;
  }

  public iciHeight;
  public bottles;
  public iciDirection;
  public curtainColor;
  public obstacleHeightAndWidth;
  public squareTypeStr;
  getObstacleInfo() {
    this.obstacleHp = this.obstacleHp <= 0 ? 0 : this.obstacleHp;
    const obstacleHpStr = `_${this.obstacleHp}`;
    const obstacleColorStr = `_${this.obstacleColor}`;
    const obstacleAllTypeStr = `O-${this.obstacleAllType}`;

    switch (this.obstacleAllType) {
      case ObstacleAllType.WoodenBox:
        return obstacleAllTypeStr + obstacleHpStr;
      case ObstacleAllType.ColorBox:
        return obstacleAllTypeStr + obstacleHpStr + obstacleColorStr;
      case ObstacleAllType.Grass:
      case ObstacleAllType.GrassLand:
      case ObstacleAllType.Egg:
        return obstacleAllTypeStr + obstacleHpStr;
      case ObstacleAllType.ColorBottle:
        return obstacleAllTypeStr + `_${this.bottles}`;
      case ObstacleAllType.Vase:
        return obstacleAllTypeStr + obstacleHpStr;
      case ObstacleAllType.Honey:
        return obstacleAllTypeStr;
      case ObstacleAllType.Icicle:
        return obstacleAllTypeStr + `_${this.iciHeight}_${this.iciDirection}`;
      case ObstacleAllType.curtain:
        return obstacleAllTypeStr + `_${this.curtainColor}_${this.obstacleHeightAndWidth}`;
      case ObstacleAllType.Oyster:
      case ObstacleAllType.Flowerpot:
      case ObstacleAllType.Stone:
      case ObstacleAllType.SafeBox:
      case ObstacleAllType.cupboard:
        return obstacleAllTypeStr + obstacleHpStr;
      case ObstacleAllType.MagicHat:
      case ObstacleAllType.MailBox:
      case ObstacleAllType.Bird:
      case ObstacleAllType.GoldCoin:
        return obstacleAllTypeStr;
      case ObstacleAllType.PorcelainPig:
      case ObstacleAllType.BirdNest:
      case ObstacleAllType.Rock:
        return obstacleAllTypeStr + obstacleHpStr;
    }

    return 'O-';
  }

  getPropInfo() {
    return `P-${this.propType}`;
  }

  setInitStr(str: string) {
    this.squareTypeStr = str;
  }

  onLoad() { }

  start() { }
}
